#include "itemdrageffect.h"

#include "uml/umlgraphicsitem.h"

ItemDragEffect::ItemDragEffect(UmlGraphicsItem *graphicsItem) : _graphicsItem(graphicsItem)
{
    this->setAcceptDrop(false);
}

void ItemDragEffect::setAcceptDrop(bool accept)
{
    if (accept) {
        this->_pixmap = QPixmap(":/icons/drop/accept_drop.png");
        this->_bgColor = QColor("#46900F");
    } else {
        this->_pixmap = QPixmap(":/icons/drop/deny_drop.png");
        this->_bgColor = QColor("#CD2B33");
    }
}

void ItemDragEffect::draw(QPainter *painter)
{
    QGraphicsEffect::drawSource(painter);

    QRectF rect = this->_graphicsItem->boundingRect();

    painter->setOpacity(.5);
    painter->fillRect(rect, this->_bgColor);

    painter->drawPixmap(rect.width() / 2 - this->_pixmap.width() / 2, rect.height() / 2 - this->_pixmap.height() / 2, this->_pixmap);
}
